package com.kbt.adapter;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import com.kbt.activity.*;
import com.kbt.listener.*;
import com.kbt.model.data.*;
import com.kbt.model.holder.OrderInfoHolder;
import com.kbt.util.data.StaticData;
import com.kbt.util.tool.BtnSetting;
import com.kbt.util.tool.RestListViewSizeTool;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhgk
 * @package: com.kbt.adapter
 * @TODO: 全部订单的适配器
 * @data: 2015/8/20 9:28
 * @version: V1.0
 */
public class OrderAllAdapter extends OrderBaseAdapter {
    private int index;
    private ArrayAdapter arr_adapter;
    private List<String> data_list;


    public OrderAllAdapter(Activity context, List<OrderBean> orderList) {
        super(context, orderList);
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        OrderInfoHolder itemHolder;

        if (convertView == null) {
            itemHolder = new OrderInfoHolder();

            LayoutInflater layoutInflater = LayoutInflater.from(context);
            convertView = layoutInflater.inflate(R.layout.good_order_quanbu_item, null);

            itemHolder.setOrderNoView((TextView) convertView.findViewById(R.id.orderNo));
            itemHolder.setOrderCreateTimeView((TextView) convertView.findViewById(R.id.createTime));

            itemHolder.setGoodListView((ListView) convertView.findViewById(R.id.goodListForOrder));

            itemHolder.setOrderStatus((TextView) convertView.findViewById(R.id.orderStatus));

            itemHolder.setOrderCount((TextView) convertView.findViewById(R.id.orderCount));
            itemHolder.setOrderFee((TextView) convertView.findViewById(R.id.totalFeel));

            itemHolder.setBtnA((Button) convertView.findViewById(R.id.orderBtn_A));
            itemHolder.setBtnB((Button) convertView.findViewById(R.id.orderBtn_B));

            itemHolder.setSh_reson((TextView) convertView.findViewById(R.id.sh_reason));
            itemHolder.setSh_status((TextView) convertView.findViewById(R.id.sh_status));

            //售后布局
            itemHolder.setCustomerServiceLay((LinearLayout) convertView.findViewById(R.id.customerServiceLay));
            //两个按钮布局
            itemHolder.setTwoBtn((LinearLayout) convertView.findViewById(R.id.twoBtn));
            //退货单号编辑
            itemHolder.setSh_txthdhLayout((LinearLayout) convertView.findViewById(R.id.sh_txkddh));
            itemHolder.setSh_thdhEdit((EditText) convertView.findViewById(R.id.sh_kddhEdit));
            itemHolder.setSh_saveBtn((Button) convertView.findViewById(R.id.kuaiDiName_saveBtn));
            //退货单号View
            itemHolder.setSh_xsthdhLayout((LinearLayout) convertView.findViewById(R.id.sh_xskddh));
            itemHolder.setSh_thdhView((TextView) convertView.findViewById(R.id.sh_kddhView));
            itemHolder.setSh_followBtn((Button) convertView.findViewById(R.id.sh_wlgz));
            itemHolder.setTextView94((TextView) convertView.findViewById(R.id.textView94));

            //退款
            itemHolder.setSh_dkthLayout((LinearLayout) convertView.findViewById(R.id.sh_skdh));
            itemHolder.setSh_tkdhEdit((TextView) convertView.findViewById(R.id.sh_tkdh));
            itemHolder.setQrBtn((Button) convertView.findViewById(R.id.sh_qrsk));
            //快递公司
            itemHolder.setLin_edit_kuaiDiName((LinearLayout) convertView.findViewById(R.id.lin_edit_kuaiDiName));
            itemHolder.setLin_kuaiDiName((LinearLayout) convertView.findViewById(R.id.lin_kuaiDiName));
            itemHolder.setEdit_kuaiDiName((EditText) convertView.findViewById(R.id.edit_kuaiDiName));
            itemHolder.setKuaiDiName((TextView) convertView.findViewById(R.id.kuaiDiName));
            //下拉
            itemHolder.setSpinner((Spinner) convertView.findViewById(R.id.spinner));

            convertView.setTag(itemHolder);
        } else {
            itemHolder = (OrderInfoHolder) convertView.getTag();
        }
        final OrderBean orderInfo = orderList.get(position);

        //下拉
        data_list = new ArrayList<String>();
        data_list.add("顺丰快递");
        data_list.add("申通快递");
        data_list.add("圆通快递");
        data_list.add("韵达快递");
        data_list.add("天天快递");
        data_list.add("EMS");
        data_list.add("中通快递");
        data_list.add("汇通快递");
        //适配器
        arr_adapter= new ArrayAdapter<String>(context,android.R.layout.simple_spinner_item, data_list);
        //设置样式
        arr_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        //加载适配器
        itemHolder.getSpinner().setAdapter(arr_adapter);

        itemHolder.getOrderNoView().setText("订单号：" + orderInfo.getOrder_no());

        itemHolder.getOrderCreateTimeView().setText(orderInfo.getOrder_create_time());

        //订单商品列表
        List<OrderGoodsListBean> goodList = orderInfo.getGoods_list();
        GoodForOrderItemAdapter itemAdapter = new GoodForOrderItemAdapter(context, goodList);
        itemHolder.getGoodListView().setAdapter(itemAdapter);
        RestListViewSizeTool.setListViewHeightBasedOnChildren(itemHolder.getGoodListView());


        itemHolder.getOrderCount().setText("共计 " + orderInfo.getGoods_count() + " 件");
        itemHolder.getOrderFee().setText(String.valueOf(orderInfo.getOrder_real_je()));

        if (orderInfo.getOrder_status().equals("1")) {
            itemHolder.getOrderStatus().setText("待付款");
            itemHolder.getCustomerServiceLay().setVisibility(View.GONE);
            itemHolder.getTwoBtn().setVisibility(View.VISIBLE);
            itemHolder.getBtnA().setText("去付款");
            itemHolder.getBtnB().setText("取消订单");
            itemHolder.getBtnB().setTextColor(Color.WHITE);
            itemHolder.getBtnA().setTextColor(Color.WHITE);
        }

        if (orderInfo.getOrder_status().equals("2")) {
            itemHolder.getOrderStatus().setText("待发货");
            itemHolder.getCustomerServiceLay().setVisibility(View.GONE);
            itemHolder.getTwoBtn().setVisibility(View.VISIBLE);
            itemHolder.getBtnA().setText("催促发货");
            itemHolder.getBtnB().setText("取消订单");
            itemHolder.getBtnB().setTextColor(Color.WHITE);
            itemHolder.getBtnA().setTextColor(Color.WHITE);

        }
        if (orderInfo.getOrder_status().equals("3")) {
            itemHolder.getOrderStatus().setText("待收货");
            itemHolder.getCustomerServiceLay().setVisibility(View.GONE);
            itemHolder.getTwoBtn().setVisibility(View.VISIBLE);
            itemHolder.getBtnA().setText("查看物流");
            itemHolder.getBtnB().setText("确认收货");
            itemHolder.getBtnB().setTextColor(Color.WHITE);
            itemHolder.getBtnA().setTextColor(Color.WHITE);
        }
        if (orderInfo.getOrder_status().equals("5")) {
            itemHolder.getOrderStatus().setText("已完成");
            itemHolder.getCustomerServiceLay().setVisibility(View.GONE);
            itemHolder.getTwoBtn().setVisibility(View.GONE);
        } else if (orderInfo.getOrder_status().equals("4")) {
            itemHolder.getCustomerServiceLay().setVisibility(View.GONE);
            itemHolder.getTwoBtn().setVisibility(View.VISIBLE);
            itemHolder.getOrderStatus().setText("待评价");
            itemHolder.getBtnA().setText("申请售后");
            itemHolder.getBtnA().setTextColor(Color.WHITE);
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("orderInfo", orderList.get(position));
            itemHolder.getBtnA().setOnClickListener(new ClickActStartActForResultListener(context,
                    AfterServiceActivity.class,StaticData.ALL_ORDER, params));

            itemHolder.getBtnB().setText("评价");
            itemHolder.getBtnB().setTextColor(Color.WHITE);

            itemHolder.getBtnB().setOnClickListener(new ClickActStartActForResultListener(context,
                    OrderJudgeActivity.class, StaticData.ALL_ORDER, params));
        } else if (orderInfo.getOrder_status().equals("7")) {
            itemHolder.getCustomerServiceLay().setVisibility(View.GONE);
            if(orderInfo.getNeed_re_pay().equals("0")){
                itemHolder.getOrderStatus().setText("已取消");
            }else if(orderInfo.getNeed_re_pay().equals("1")){
                itemHolder.getOrderStatus().setText("已取消(已退款)");
            }else if(orderInfo.getNeed_re_pay().equals("2")){
                itemHolder.getOrderStatus().setText("已取消(退款中)");
            }
            itemHolder.getTwoBtn().setVisibility(View.GONE);
        }
        if (orderInfo.getOrder_status().equals("6")) {
            itemHolder.getOrderStatus().setText("售后");
            itemHolder.getTwoBtn().setVisibility(View.GONE);
        }
        final ShouHouInfoBean sh_info = orderInfo.getSh_info();
        if (sh_info != null&&orderInfo.getOrder_status().equals("6")) {
            itemHolder.getCustomerServiceLay().setVisibility(View.VISIBLE);
            //根据订单状态展示不同的页面
            if (sh_info.getApply_type() == 1) {//商品补发
                itemHolder.getSh_reson().setText("商品补发");
                if (sh_info.getBf_sh_jd() == 1) {//卖家待处理
                    itemHolder.getSh_status().setText("卖家待处理");
                    itemHolder.getSh_txthdhLayout().setVisibility(View.GONE);//编辑退货单号
                    itemHolder.getSh_xsthdhLayout().setVisibility(View.GONE);//退货单号
                    itemHolder.getSh_dkthLayout().setVisibility(View.GONE);//退款单号
                    itemHolder.getLin_edit_kuaiDiName().setVisibility(View.GONE);//编辑快递公司
                    itemHolder.getLin_kuaiDiName().setVisibility(View.GONE);//显示快递公司
                    itemHolder.getTwoBtn().setVisibility(View.GONE);//查看物流和确认收货两个按钮
                } else if (sh_info.getBf_sh_jd() == 5) {//卖家已补发
                    itemHolder.getSh_status().setText("卖家已补发");
                    itemHolder.getTextView94().setText("补货单号：");
                    itemHolder.getSh_followBtn().setVisibility(View.GONE);//跟踪按钮
                    itemHolder.getSh_xsthdhLayout().setVisibility(View.VISIBLE);//补货单号
                    itemHolder.getLin_kuaiDiName().setVisibility(View.VISIBLE);//显示快递公司
                    itemHolder.getTwoBtn().setVisibility(View.VISIBLE);//查看物流和确认收货两个按钮
                    itemHolder.getSh_txthdhLayout().setVisibility(View.GONE);//编辑退货单号
                    itemHolder.getSh_dkthLayout().setVisibility(View.GONE);//退款单号
                    itemHolder.getLin_edit_kuaiDiName().setVisibility(View.GONE);//编辑快递公司
                    itemHolder.getBtnA().setText("查看物流");
                    itemHolder.getBtnB().setText("确认收货");
                    itemHolder.getSh_thdhView().setText(sh_info.getBf_kd_dh()+"");
                    itemHolder.getKuaiDiName().setText(sh_info.getBf_kd_gsmc()+"");
                    itemHolder.getBtnB().setTextColor(Color.WHITE);
                    itemHolder.getBtnA().setTextColor(Color.WHITE);
                }else if (sh_info.getBf_sh_jd() == 2) {//卖家已接受
                    itemHolder.getSh_status().setText("卖家已接受");
                    itemHolder.getSh_txthdhLayout().setVisibility(View.GONE);//编辑退货单号
                    itemHolder.getSh_xsthdhLayout().setVisibility(View.GONE);//退货单号
                    itemHolder.getSh_dkthLayout().setVisibility(View.GONE);//退款单号
                    itemHolder.getLin_edit_kuaiDiName().setVisibility(View.GONE);//编辑快递公司
                    itemHolder.getLin_kuaiDiName().setVisibility(View.GONE);//显示快递公司
                    itemHolder.getTwoBtn().setVisibility(View.GONE);//查看物流和确认收货两个按钮
                }
            } else if (sh_info.getApply_type() == 2) {//申请换货
                itemHolder.getSh_reson().setText("申请换货");
                itemHolder.getSh_dkthLayout().setVisibility(View.GONE);
                if (sh_info.getHh_sh_jd() == 1) {//卖家待处理
                    itemHolder.getSh_status().setText("卖家待处理");
                    itemHolder.getSh_txthdhLayout().setVisibility(View.GONE);//编辑退货单号
                    itemHolder.getSh_xsthdhLayout().setVisibility(View.GONE);//退货单号
                    itemHolder.getSh_dkthLayout().setVisibility(View.GONE);//退款单号
                    itemHolder.getLin_edit_kuaiDiName().setVisibility(View.GONE);//编辑快递公司
                    itemHolder.getLin_kuaiDiName().setVisibility(View.GONE);//显示快递公司
                    itemHolder.getTwoBtn().setVisibility(View.GONE);//查看物流和确认收货两个按钮
                } else if (sh_info.getHh_sh_jd() == 2) {//卖家已接受
                    itemHolder.getSh_status().setText("卖家已接受");
                    itemHolder.getSh_txthdhLayout().setVisibility(View.VISIBLE);//编辑退货单号
                    itemHolder.getLin_edit_kuaiDiName().setVisibility(View.VISIBLE);//编辑快递公司
                    itemHolder.getSh_xsthdhLayout().setVisibility(View.GONE);//退货单号
                    itemHolder.getSh_dkthLayout().setVisibility(View.GONE);//退款单号
                    itemHolder.getLin_kuaiDiName().setVisibility(View.GONE);//显示快递公司
                    itemHolder.getTwoBtn().setVisibility(View.GONE);//查看物流和确认收货两个按钮
                } else if (sh_info.getHh_sh_jd() == 4) {//卖家已收货
                    itemHolder.getSh_status().setText("卖家已收货");
                    itemHolder.getSh_txthdhLayout().setVisibility(View.GONE);//编辑退货单号
                    itemHolder.getSh_xsthdhLayout().setVisibility(View.GONE);//退货单号
                    itemHolder.getSh_dkthLayout().setVisibility(View.GONE);//退款单号
                    itemHolder.getLin_edit_kuaiDiName().setVisibility(View.GONE);//编辑快递公司
                    itemHolder.getLin_kuaiDiName().setVisibility(View.GONE);//显示快递公司
                    itemHolder.getTwoBtn().setVisibility(View.GONE);//查看物流和确认收货两个按钮
                } else if (sh_info.getHh_sh_jd() == 3) {
                    itemHolder.getSh_status().setText("卖家待收货");
                    itemHolder.getSh_xsthdhLayout().setVisibility(View.VISIBLE);//退货单号
                    itemHolder.getLin_kuaiDiName().setVisibility(View.VISIBLE);//显示快递公司
                    itemHolder.getSh_txthdhLayout().setVisibility(View.GONE);//编辑退货单号
                    itemHolder.getLin_edit_kuaiDiName().setVisibility(View.GONE);//编辑快递公司
                    itemHolder.getSh_dkthLayout().setVisibility(View.GONE);//退款单号
                    itemHolder.getTwoBtn().setVisibility(View.GONE);//查看物流和确认收货两个按钮
                    itemHolder.getSh_thdhView().setText(sh_info.getTh_kd_dh() + "");
                    itemHolder.getKuaiDiName().setText(sh_info.getTh_kd_gsmc() + "");
                } else if (sh_info.getHh_sh_jd() == 5) {
                    itemHolder.getSh_status().setText("卖家已发货");
                    itemHolder.getTextView94().setText("补货单号：");
                    itemHolder.getSh_followBtn().setVisibility(View.GONE);//跟踪按钮
                    itemHolder.getSh_xsthdhLayout().setVisibility(View.VISIBLE);//补货单号
                    itemHolder.getLin_kuaiDiName().setVisibility(View.VISIBLE);//显示快递公司
                    itemHolder.getTwoBtn().setVisibility(View.VISIBLE);//查看物流和确认收货两个按钮
                    itemHolder.getSh_txthdhLayout().setVisibility(View.GONE);//编辑退货单号
                    itemHolder.getLin_edit_kuaiDiName().setVisibility(View.GONE);//编辑快递公司
                    itemHolder.getSh_dkthLayout().setVisibility(View.GONE);//退款单号
                    itemHolder.getBtnA().setText("查看物流");
                    itemHolder.getBtnB().setText("确认收货");
                    itemHolder.getSh_thdhView().setText(sh_info.getBf_kd_dh() + "");
                    itemHolder.getKuaiDiName().setText(sh_info.getBf_kd_gsmc() + "");
                    itemHolder.getBtnB().setTextColor(Color.WHITE);
                    itemHolder.getBtnA().setTextColor(Color.WHITE);
                }
            } else if (sh_info.getApply_type() == 3) {//申请退款
                itemHolder.getSh_reson().setText("申请退款");
                if (sh_info.getTk_sh_jd() == 1) {//卖家待处理
                    itemHolder.getSh_status().setText("卖家待处理");
                    itemHolder.getSh_txthdhLayout().setVisibility(View.GONE);//编辑退货单号
                    itemHolder.getSh_xsthdhLayout().setVisibility(View.GONE);//退货单号
                    itemHolder.getSh_dkthLayout().setVisibility(View.GONE);//退款单号
                    itemHolder.getLin_edit_kuaiDiName().setVisibility(View.GONE);//编辑快递公司
                    itemHolder.getLin_kuaiDiName().setVisibility(View.GONE);//显示快递公司
                    itemHolder.getTwoBtn().setVisibility(View.GONE);//查看物流和确认收货两个按钮
                } else if (sh_info.getTk_sh_jd() == 2) {//卖家已接受
                    itemHolder.getSh_status().setText("卖家已接受");
                    itemHolder.getSh_txthdhLayout().setVisibility(View.VISIBLE);//编辑退货单号
                    itemHolder.getLin_edit_kuaiDiName().setVisibility(View.VISIBLE);//编辑快递公司
                    itemHolder.getSh_xsthdhLayout().setVisibility(View.GONE);//退货单号
                    itemHolder.getSh_dkthLayout().setVisibility(View.GONE);//退款单号
                    itemHolder.getLin_kuaiDiName().setVisibility(View.GONE);//显示快递公司
                    itemHolder.getTwoBtn().setVisibility(View.GONE);//查看物流和确认收货两个按钮
                } else if (sh_info.getTk_sh_jd() == 3) {//卖家待收货
                    itemHolder.getSh_status().setText("卖家待收货");
                    itemHolder.getSh_xsthdhLayout().setVisibility(View.VISIBLE);//退货单号
                    itemHolder.getLin_kuaiDiName().setVisibility(View.VISIBLE);//显示快递公司
                    itemHolder.getSh_txthdhLayout().setVisibility(View.GONE);//编辑退货单号
                    itemHolder.getLin_edit_kuaiDiName().setVisibility(View.GONE);//编辑快递公司
                    itemHolder.getSh_dkthLayout().setVisibility(View.GONE);//退款单号
                    itemHolder.getTwoBtn().setVisibility(View.GONE);//查看物流和确认收货两个按钮
                    itemHolder.getSh_thdhView().setText(sh_info.getTh_kd_dh() + "");
                    itemHolder.getKuaiDiName().setText(sh_info.getTh_kd_gsmc() + "");
                } else if (sh_info.getTk_sh_jd() == 4) {//卖家已收货
                    itemHolder.getSh_status().setText("卖家已收货");
                    itemHolder.getSh_txthdhLayout().setVisibility(View.GONE);//编辑退货单号
                    itemHolder.getSh_xsthdhLayout().setVisibility(View.GONE);//退货单号
                    itemHolder.getSh_dkthLayout().setVisibility(View.GONE);//退款单号
                    itemHolder.getLin_edit_kuaiDiName().setVisibility(View.GONE);//编辑快递公司
                    itemHolder.getLin_kuaiDiName().setVisibility(View.GONE);//显示快递公司
                    itemHolder.getTwoBtn().setVisibility(View.GONE);//查看物流和确认收货两个按钮
                } else if (sh_info.getTk_sh_jd() == 5) {////卖家已退款
                    itemHolder.getSh_status().setText("卖家已退款");
                    itemHolder.getSh_dkthLayout().setVisibility(View.VISIBLE);//退款单号
                    itemHolder.getSh_txthdhLayout().setVisibility(View.GONE);//编辑退货单号
                    itemHolder.getSh_xsthdhLayout().setVisibility(View.GONE);//退货单号
                    itemHolder.getLin_edit_kuaiDiName().setVisibility(View.GONE);//编辑快递公司
                    itemHolder.getLin_kuaiDiName().setVisibility(View.GONE);//显示快递公司
                    itemHolder.getTwoBtn().setVisibility(View.GONE);//查看物流和确认收货两个按钮
                    itemHolder.getSh_tkdhEdit().setText(sh_info.getTk_no() + "");
                }
            }
        }

        if (itemHolder.getBtnA().getText().equals("去付款")) {
            itemHolder.getBtnA().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    List<ShopCarBean> list = new ArrayList<ShopCarBean>();
                    ShopCarBean shopCarBean = null;
                    for (int i = 0; i < orderInfo.getGoods_list().size(); i++) {
                        shopCarBean = new ShopCarBean();
                        shopCarBean.setGoods_new_price(Float.parseFloat(orderInfo.getGoods_list().get(i).getGoods_new_price()));
                        shopCarBean.setGoods_count(orderInfo.getGoods_list().get(i).getGoods_count());
                        shopCarBean.setGoods_title(orderInfo.getGoods_list().get(i).getGoods_title());
                        shopCarBean.setGoods_icon(orderInfo.getGoods_list().get(i).getGoods_icon());
                        shopCarBean.setGoods_id(orderInfo.getGoods_list().get(i).getGoods_id());
                        shopCarBean.setGoods_tm(orderInfo.getGoods_list().get(i).getGoods_tm());
                        shopCarBean.setGoods_no(orderInfo.getGoods_list().get(i).getGoods_no());
                        list.add(shopCarBean);
                    }
                    Intent intent = new Intent(context, GoodForPayActivity.class);
                    intent.putExtra("biaoji", "noPayMoney");
                    intent.putExtra("list", (Serializable) list);
                    intent.putExtra("order_jf_sub_je",orderInfo.getOrder_jf_sub_je());
                    intent.putExtra("orderNo",orderInfo.getOrder_no());
                    context.startActivity(intent);
//                    context.finish();
                }
            });

        }
        if (itemHolder.getBtnA().getText().equals("催促发货")) {
            itemHolder.getBtnA().setOnClickListener(new ClickToPressSendOrderListener(context, orderList, OrderAllAdapter.this, position));
        }
        if (itemHolder.getBtnA().getText().equals("查看物流")) {
            itemHolder.getBtnA().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context,KuaiDiActivity.class);
                    if(sh_info==null) {
                        intent.putExtra("kd_name", orderInfo.getOrder_kd_name());
                        intent.putExtra("dh", orderInfo.getOrder_kd_dh());
                        intent.putExtra("bm", orderInfo.getOrder_kd_bm());
                    }else{
                        intent.putExtra("kd_name", sh_info.getBf_kd_gsmc());
                        intent.putExtra("dh", sh_info.getBf_kd_dh());
                        intent.putExtra("bm", sh_info.getBf_kd_gs());//bf_kd_gs
                    }
                    context.startActivity(intent);
                }
            });

        }
        if(itemHolder.getSh_followBtn().getText().toString().equals("跟踪")){
            itemHolder.getSh_followBtn().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent  = new Intent(context,KuaiDiActivity.class);
                    if(sh_info==null) {
                        intent.putExtra("kd_name", orderInfo.getOrder_kd_name());
                        intent.putExtra("dh", orderInfo.getOrder_kd_dh());
                        intent.putExtra("bm",orderInfo.getOrder_kd_bm());
                    }else{
                        intent.putExtra("kd_name", sh_info.getTh_kd_gsmc());
                        intent.putExtra("dh", sh_info.getTh_kd_dh());
                        intent.putExtra("bm", sh_info.getTh_kd_gs());//th_kd_gs

                    }
                    context.startActivity(intent);
                }
            });
        }

        Map<String, Object> params = new HashMap<String, Object>();
        params.put("orderInfo", orderList.get(position));
        if (itemHolder.getBtnB().getText().equals("申请售后")) {
            itemHolder.getBtnB().setOnClickListener(new ClickActStartActForResultListener(context,
                    AfterServiceActivity.class, StaticData.ALL_ORDER, params));
        }
        if (itemHolder.getBtnA().getText().equals("评价")) {
            itemHolder.getBtnA().setOnClickListener(new ClickActStartActForResultListener(context,
                    OrderJudgeActivity.class, StaticData.ALL_ORDER, params));
        }

        if (itemHolder.getBtnB().getText().equals("取消订单")) {
            itemHolder.getBtnB().setOnClickListener(new ClickConfirmOrderListener(context, convertView,
                    OrderAllAdapter.this, orderList, position, StaticData.POPWINDOW_CANCEL_ORDER));
        }
        if (itemHolder.getBtnB().getText().equals("确认收货")) {
            itemHolder.getBtnB().setOnClickListener(new ClickConfirmOrderListener(context, convertView,
                    OrderAllAdapter.this, orderList, position, StaticData.POPWINDOW_CONFIRM_ORDER));
        }
        itemHolder.getSh_saveBtn().setOnClickListener(new SaveKuaiDiInfoListener(context,itemHolder.getSpinner(),itemHolder.getSh_thdhEdit(),itemHolder.getSh_saveBtn(),orderInfo));

        //处理edittext焦点问题
        itemHolder.getSh_thdhEdit().setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    index = position;
                }
                return false;
            }
        });
        itemHolder.getSh_thdhEdit().clearFocus();
        if (index != -1 && index == position) {
            // 如果当前的行下标和点击事件中保存的index一致，手动为EditText设置焦点。
            itemHolder.getSh_thdhEdit().requestFocus();
        }
        itemHolder.getSh_thdhEdit().setSelection(itemHolder.getSh_thdhEdit().getText().length());


        return super.getView(position, convertView, parent);
    }
}
